package com.huaxin.controller;

import com.huaxin.entity.ProductInfo;
import com.huaxin.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author Corday
 * @Create 2020/5/22 16:23
 * @商品管理控制器
 */
@Controller
public class ProductController {
    @Resource
    private ProductService productService;

    //////1.以下映射动作，实现切换并且携带数据////////
    @RequestMapping(value = "/goindex")
    public String queryProducts(Model model) {
//     (1)查热门
        List<ProductInfo> products1 = productService.queryByStatus(1);
//     (2)查抢购
        List<ProductInfo> products2 = productService.queryByStatus(2);
        //存入缓存，方便前端jsp页面取数据
//        热门商品
        model.addAttribute("products1", products1);
//        抢购端品
        model.addAttribute("products2", products2);
//        System.out.println("名称:"+products1.get(0).getName());
        //WEB-INF/jsp/back_test.jsp
        //return "WEB-INF/jsp/admin.jsp";
        return "index";
    }

    // 查询其它更多商品
    @RequestMapping(value = "/jmgw")
    public String queryAll(Map map) {
//        接商品状态查询
        List<ProductInfo> list = productService.queryByStatus(3);
        map.put("list", list);
//         返回一个逻辑视图
        return "my_all";
    }//queryall


}
